@section('css')
    <link rel="stylesheet" href="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.css')}}">
    {{--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">--}}
    <link rel="stylesheet" href="{{asset('admin-lte/plugins/datetimepicker/css/bootstrap-datetimepicker.css')}}">
    <style>
        .form-group{
            display: flex;
        }
        .form-group .control-label{
            text-align:right;
        }
        .portlet>.portlet-title {
            border-bottom: 2px solid #eef1f5;;
        }
        .help-block-error,.required{
            color:red;
        }

        .glyphicon-arrow-left{
            background-position: -240px -96px!important;
        }

        .glyphicon-arrow-right{
            background-position: -264px -96px!important;
        }

        .glyphicon{
            display: inline-block;
            width: 14px;
            height: 14px;
            margin-top: 1px;
            line-height: 14px;
            vertical-align: text-top;
            background-image: url(http://cdn.bootcss.com/twitter-bootstrap/2.2.2/img/glyphicons-halflings.png);
            background-position: 14px 14px;
            background-repeat: no-repeat;
        }
    </style>
@stop
<div class="row">
    <div class="col-md-12">
        <div class="portlet light portlet-fit portlet-form bordered">
            <div class="portlet-title">
                <div class="caption">
                    <i class=" icon-layers font-green"></i>
                    <span class="caption-subject font-green sbold">促销内容</span>
                </div>
            </div>
            <div class="portlet-body">
                <form action="{{$action=='create'?url('admin/coupon/create_coupon'):url('admin/coupon/edit_coupon') }}" class="form-horizontal" id="validation-form" method="post">
                    <div class="form-body">
                        <input type="hidden" name="Coupon[coupon_id]" value="<?= isset($coupon_row['coupon_id'])?$coupon_row['coupon_id']:''?>">
                        <div class="form-group">
                            <label class="control-label col-md-3">优惠券名称
                                <span class="required"> * </span>
                            </label>
                            <div class="col-md-3">
                                <input type="text" name="Coupon[title]" class="form-control"
                                       value="<?php echo isset($coupon_row['title'])?$coupon_row['title']:'';?>"/>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label col-md-3">开始时间
                                <span class="required"> * </span>
                            </label>
                            <div class="col-md-3">
                                <input readonly type="text" class="form-control create_time_start" name="Coupon[start_time]"
                                       value="<?php echo isset($coupon_row)&&$coupon_row['start_time']?date('Y-m-d H:i',$coupon_row['start_time']):'';?>">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="control-label col-md-3">结束时间
                                <span class="required"> * </span>
                            </label>
                            <div class="col-md-3">
                                <input readonly type="text" class="form-control create_time_end" name="Coupon[end_time]"
                                       value="<?php echo isset($coupon_row)&&$coupon_row['end_time']?date('Y-m-d H:i', $coupon_row['end_time']):'';?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3">每人限领
                                <span class="required"> * </span>
                            </label>
                            <div class="col-md-3">
                                @if(isset($coupon_row))
                                    <input placeholder="不填不限数量" type="text" class="form-control" name="Coupon[limit_per_get]"
                                           value="<?= $coupon_row['limit_per_get']==-1?'':$coupon_row['limit_per_get']?>">
                                @else
                                    <input placeholder="不填不限数量" type="text" class="form-control" name="Coupon[limit_per_get]" value="">
                                @endif

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3">发放数量
                                <span class="required"> * </span>
                            </label>
                            <div class="col-md-3">
                                @if(isset($coupon_row))
                                    <input placeholder="不填不限数量" type="text" class="form-control create_time_start" name="Coupon[send_num]"
                                           value="<?= $coupon_row['send_num']==-1?'':$coupon_row['send_num']?>">
                                @else
                                    <input placeholder="不填不限数量" type="text" class="form-control create_time_start" name="Coupon[send_num]" value="">
                                @endif

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-md-3">促销规则
                                <span class="required"> * </span>
                            </label>
                            <div class="col-md-3">
                                <select class="form-control" name="Coupon[rule_id]">
                                    <option value="0">--请选择促销规则--</option>
                                    <?php foreach ($rule_list as $v):?>
                                    <option value="<?php echo $v['rule_id'];?>"
                                    <?php echo isset($coupon_row['rule_id'])&&$coupon_row['rule_id']==$v['rule_id']?'selected':'';?>><?php echo $v['title'];?></option>
                                    <?php endforeach;?>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="form-actions">
                        <div class="row">
                            <div class="offset-md-3 col-md-9">
                                <button type="submit" class="btn btn-success">提交</button>
                                <button type="reset" class="btn btn-default">取消</button>
                            </div>
                        </div>
                    </div>
                    {{csrf_field()}}
                </form>
            </div>
        </div>
    </div>
</div>

@section('script')
<script src="{{asset('admin-lte/plugins/datatables/jquery.dataTables.js')}}"></script>
<script src="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.js')}}"></script>

{{--jqueryVlaition插件--}}
<script src="{{asset('admin-lte/plugins/jquery-validation/js/jquery.validate.js')}}"></script>
<script src="{{asset('js/spu/form-validate.js')}}"></script>

{{--layer插件--}}
<script src='{{asset("admin-lte/plugins/layer-v3.1.1/layer.js")}}' type='text/javascript'></script>

{{--引入bootstrap datetimepicker插件--}}
<script src="{{asset('admin-lte/plugins/datetimepicker/js/bootstrap-datetimepicker.js')}}"></script>
<script src="{{asset('admin-lte/plugins/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js')}}"></script>
<script>

    $('input[name="Coupon[start_time]"],input[name="Coupon[end_time]"]').datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        autoclose : true,
        language:  'zh-CN',
    })

    //表单验证
    validate(
        {
            'Coupon[title]':{'required': true},
//            'Coupon[code]':{'required': true},
            'Coupon[start_time]':{'required': true},
            'Coupon[end_time]':{'required': true},
//            'Coupon[send_type]':{'required': true, min:1},
            'Coupon[rule_id]':{'required': true, min:1}
        },
        {
            'Coupon[title]':{'required': '优惠券名称不能为空'},
//            'Coupon[code]':{'required': '券码不能为空'},
            'Coupon[start_time]':{'required': '开始时间不能为空'},
            'Coupon[end_time]':{'required': '结束时间不能为空'},
//            'Coupon[send_type]':{'required': '发放类型不能为空', min:'发放类型不能为空'},
            'Coupon[rule_id]':{'required': '优惠类型不能为空', min:'促销规格不能为空'}
        }
    );

    //订单时间
//    if ($('#validation-form').html()) {
//        dateTimePicker($('.create_time_start'));
//        dateTimePicker($('.create_time_end'));
//    }

    //优惠券发放
    $('.coupon-send2').on('click', function(){
        var coupon_id = $('.coupon-id').val();
        var coupon_send = $('.coupon-send').val();
        App.blockUI({
            target: 'body',
            animate: true
        });
        $.post(
            '?r=sales/coupon/sendsave',
            {'coupon_id':coupon_id, 'send_num':coupon_send,'_csrf': $('.request-csrf').val()},
            function (res) {
                App.unblockUI('body');
                alert(res.msg);
                if (res.code == 200) {
                    location.reload();
                } else {
                    return false;
                }
            },'json '
        );
    });
</script>
@stop